/*-------------------------------------------------------------------------------------------------------------------------------------------
Program: balance_test_indiv_charact.do
Comments: This program produces the results used to create balance table (Table 8) for individual characteristics such as gender, employment, age, years of educ, hh income, and religion. The formatted table is produced using the collapsed data generated in line 63 and line 95 in this program.
----------------------------------------------------------------------------------------------------------------------------------------*/
*version Stata/SE 17.0

clear all
set more off
macro drop _all

cd "/Volumes/GoogleDrive/My Drive/Documents/JMP/Work/Tables/tables_replication" 


capture log close


use 				"merged_v0.31_replication.dta" , clear

encode session_id, gen(sess_id)
xtset sess_id

gen percent_female = female*100
gen percent_HC  = HC*100
gen percent_employed = work*100
gen inc				= hh_inc/1000
gen percent_hindu = hindu*100
gen percent_christian = christian*100
gen percent_vil 	= village_org*100
label var  percent_female     		"Female(\%)"
label var  percent_employed			"Employed(\%)"
label var  percent_hindu			"Hindu(\%)"
label var  percent_christian		"Christian(\%)" 
label var  percent_vil				"Part of a village organization(\%)"
label var  amt_sent1				"Amount sent in round 1"
label var  belief_oth1				"Belief about majority's sending"	
label var  	inc						"Monthly household income (in '000's)"

*********************************************************************************************
**INFO 40 BALANCE
*********************************************************************************************
forvalues i = 40(20)40  {

foreach yvar in percent_female 	///
				percent_employed	age 	///
				educ 	 inc  				///
				percent_hindu percent_christian ///
				 {


/****GLS with session level random effects for amt_sent1 with only fine != 10 *****/

xtreg 			`yvar' 	rule0 rule100   if norm == `i' , re vce(cluster sess_id)
xtreg 			`yvar' 	rule60 rule100  if norm == `i' , re vce(cluster sess_id)
predict 		 `yvar'_`i'_hat  if norm == `i'
predict 		 `yvar'_`i'_se  if norm == `i', stdp

					}
}
	
preserve			
collapse	(mean)	percent_female	 (sem) sepercent_female = percent_female	///
			(mean) percent_employed  (sem) sepercent_employed = percent_employed /// 
			(mean) age				  (sem) seage = age		///
			(mean)	educ 			(sem) seeduc= educ								///
			(mean) inc				(sem) seinc = inc					 		///
			(mean)	percent_hindu 	(sem) sepercent_hindu = percent_hindu		///
			(mean) percent_christian (sem) sepercent_christian = percent_christian ///
			if norm==40, by(rule)
restore		

*********************************************************************************************
**INFO 60 BALANCE
*********************************************************************************************

forvalues i = 60(20)60  {

foreach yvar in percent_female 	///
				percent_employed	age 	///
				educ 	 inc  				///
				percent_hindu percent_christian ///
				 {


/****GLS with session level random effects for amt_sent1 with only fine != 10 *****/

xtreg 			`yvar' 	rule0 rule100   if norm == `i' , re vce(cluster sess_id)
xtreg 			`yvar' 	rule60 rule100  if norm == `i' , re vce(cluster sess_id)

					}
}
	
	preserve		
collapse    (mean)	percent_female	 (sem) sepercent_female = percent_female	///
			(mean) percent_employed  (sem) sepercent_employed = percent_employed /// 
			(mean) age				  (sem) seage = age		///
			(mean)	educ 			(sem) seeduc= educ								///
			(mean) inc				(sem) seinc = inc					 		///
			(mean)	percent_hindu 	(sem) sepercent_hindu = percent_hindu		///
			(mean) percent_christian (sem) sepercent_christian = percent_christian ///
			if norm==60, by(rule)
	restore		
			

